package com.ruoyi.car.controller.parts;

import java.util.List;

import com.car.pojo.TbPartModelProperty;
import com.ruoyi.car.service.parts.ITbPartModelPropertyService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电池模组性能参数列表Controller
 *
 * @author 韩昊昌
 * @date 2020-06-25
 */
@Controller
@RequestMapping("/modelProperty/modelProperty")
public class TbPartModelPropertyController extends BaseController
{
    private String prefix = "parts/modelProperty";

    @Autowired
    private ITbPartModelPropertyService tbPartModelPropertyService;

    @RequiresPermissions("modelProperty:modelProperty:view")
    @GetMapping()
    public String modelProperty()
    {
        return prefix + "/modelProperty";
    }

    /**
     * 查询电池模组性能参数列表列表
     */
    @RequiresPermissions("modelProperty:modelProperty:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbPartModelProperty tbPartModelProperty)
    {
        startPage();
        List<TbPartModelProperty> list = tbPartModelPropertyService.selectTbPartModelPropertyList(tbPartModelProperty);
        return getDataTable(list);
    }

    /**
     * 导出电池模组性能参数列表列表
     */
    @RequiresPermissions("modelProperty:modelProperty:export")
    @Log(title = "电池模组性能参数列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbPartModelProperty tbPartModelProperty)
    {
        List<TbPartModelProperty> list = tbPartModelPropertyService.selectTbPartModelPropertyList(tbPartModelProperty);
        ExcelUtil<TbPartModelProperty> util = new ExcelUtil<TbPartModelProperty>(TbPartModelProperty.class);
        return util.exportExcel(list, "modelProperty");
    }

    /**
     * 新增电池模组性能参数列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电池模组性能参数列表
     */
    @RequiresPermissions("modelProperty:modelProperty:add")
    @Log(title = "电池模组性能参数列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbPartModelProperty tbPartModelProperty)
    {
        return toAjax(tbPartModelPropertyService.insertTbPartModelProperty(tbPartModelProperty));
    }

    /**
     * 修改电池模组性能参数列表
     */
    @GetMapping("/edit/{propertyId}")
    public String edit(@PathVariable("propertyId") Long propertyId, ModelMap mmap)
    {
        TbPartModelProperty tbPartModelProperty = tbPartModelPropertyService.selectTbPartModelPropertyById(propertyId);
        mmap.put("tbPartModelProperty", tbPartModelProperty);
        return prefix + "/edit";
    }

    /**
     * 修改保存电池模组性能参数列表
     */
    @RequiresPermissions("modelProperty:modelProperty:edit")
    @Log(title = "电池模组性能参数列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbPartModelProperty tbPartModelProperty)
    {
        return toAjax(tbPartModelPropertyService.updateTbPartModelProperty(tbPartModelProperty));
    }

    /**
     * 删除电池模组性能参数列表
     */
    @RequiresPermissions("modelProperty:modelProperty:remove")
    @Log(title = "电池模组性能参数列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbPartModelPropertyService.deleteTbPartModelPropertyByIds(ids));
    }

    @GetMapping("/findOne/{id}")
    @ResponseBody
    public TbPartModelProperty findOne(@PathVariable("id") String id)
    {
        long l = Long.parseLong(id);
        TbPartModelProperty tbPartModelProperty = tbPartModelPropertyService.selectTbPartModelPropertyById(l);

        return tbPartModelProperty;
    }
}
